﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyThuoc.DAL
{
   public class ThuocDAL:KetNoiDAL
    {
       public DataTable SelectAll_Thuoc()
       {
           SqlCommand cmd = new SqlCommand("SelectAll_Thuoc", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public  DataTable SearchThuocByCondition(string keyword)
       {
           SqlCommand cmd = new SqlCommand("SearchThuocByCondition", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@keyword", keyword);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SelectIDThuoc(int IdThuoc)
       {
           SqlCommand cmd = new SqlCommand("SelectID_Thuoc", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDThuoc", IdThuoc);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable LayTenThuocTheoIDs(int IdThuoc)
       {
           SqlCommand cmd = new SqlCommand("SelectID_Thuoc", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDThuoc", IdThuoc);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public int InsertThuoc(string TenThuoc, string DVT, string DVTMua, decimal HeSoQD, string LoaiThuoc, string NhomThuoc, string DuongDung, string CongDung, string ChongChiDinh, string DieuKienBaoQuan, int IdNCC, int ThoiHanSuDung, int SoLuongMin)
       {

           SqlCommand cmd = new SqlCommand("Insert_Thuoc", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               //cmd.Parameters.AddWithValue("@IDThuoc", IdThuoc);
               cmd.Parameters.AddWithValue("@TenThuoc", TenThuoc);
               cmd.Parameters.AddWithValue("@Dvt", DVT);
               cmd.Parameters.AddWithValue("@DvtMua", DVTMua);
               cmd.Parameters.AddWithValue("@HeSoQD", HeSoQD);
               cmd.Parameters.AddWithValue("@LoaiThuoc", LoaiThuoc);
               cmd.Parameters.AddWithValue("@NhomThuoc", NhomThuoc);
               cmd.Parameters.AddWithValue("@DuongDung", DuongDung);
               cmd.Parameters.AddWithValue("@CongDung", CongDung);
               cmd.Parameters.AddWithValue("@ChongChiDinh", ChongChiDinh);
               cmd.Parameters.AddWithValue("@DieuKienBaoQuan", DieuKienBaoQuan);
               cmd.Parameters.AddWithValue("@IDNCC", IdNCC);
               cmd.Parameters.AddWithValue("@ThoiHanSuDung", ThoiHanSuDung);
               cmd.Parameters.AddWithValue("@SoLuongMin", SoLuongMin);
             return  cmd.ExecuteNonQuery();
          
       }
       public int UpdateThuoc(int IdThuoc,string TenThuoc, string DVT, string DVTMua, decimal HeSoQD, string LoaiThuoc, string NhomThuoc, string DuongDung, string CongDung, string ChongChiDinh, string DieuKienBaoQuan, int IdNCC, int ThoiHanSuDung, int SoLuongMin)
       {

               SqlCommand cmd = new SqlCommand("Update_Thuoc", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDThuoc", IdThuoc);
               cmd.Parameters.AddWithValue("@TenThuoc", TenThuoc);
               cmd.Parameters.AddWithValue("@Dvt", DVT);
               cmd.Parameters.AddWithValue("@DvtMua", DVTMua);
               cmd.Parameters.AddWithValue("@HeSoQD", HeSoQD);
               cmd.Parameters.AddWithValue("@LoaiThuoc", LoaiThuoc);
               cmd.Parameters.AddWithValue("@NhomThuoc", NhomThuoc);
               cmd.Parameters.AddWithValue("@DuongDung", DuongDung);
               cmd.Parameters.AddWithValue("@CongDung", CongDung);
               cmd.Parameters.AddWithValue("@ChongChiDinh", ChongChiDinh);
               cmd.Parameters.AddWithValue("@DieuKienBaoQuan", DieuKienBaoQuan);
               cmd.Parameters.AddWithValue("@IDNCC", IdNCC);
               cmd.Parameters.AddWithValue("@ThoiHanSuDung", ThoiHanSuDung);
               cmd.Parameters.AddWithValue("@SoLuongMin", SoLuongMin);
              return cmd.ExecuteNonQuery();
          
       }
       public int DeleteThuoc(int IdThuoc)
       {

             SqlCommand cmd = new SqlCommand("Delete_Thuoc", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDThuoc", IdThuoc);
             return  cmd.ExecuteNonQuery();
            
       }
    }
}
